package com.lwy.springbootdemo01.config;


import com.lwy.springbootdemo01.interceptor.Myinterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Spring mvc 配置类
 */
//实现 WebMvcConfigurer 来完成对 拦截器的添加
// 重写addInterceptors的方法来添加自定义拦截器
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    //注册拦截器
    @Bean
    public Myinterceptor myinterceptor(){
        return new Myinterceptor();
    }

    //添加拦截器到拦截器链
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //   addInterceptor   所添加的拦截器
        //  addPathPatterns    拦截哪些东西的配置   /* 是拦截所有请求路径
        registry.addInterceptor(myinterceptor()).addPathPatterns("/*");
    }
}
